package xyz.weizhi.config;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @Author milian
 * @Date 2021/9/12 0012 21:24
 */
public class ServletContainersInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
    /**
     * @Author milian
     * @Description 解决乱码
     * @Date 11:06 2021/9/13 0013
     * @Param []
     * @return javax.servlet.Filter[]
     **/
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        return new Filter[]{filter};
    }
    //@Override
    //protected WebApplicationContext createServletApplicationContext() {
    //    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    //    context.register(SpringMvcConfig.class);
    //    return context;
    //}
    //
    //@Override
    //protected String[] getServletMappings() {
    //    return new String[]{"/"};
    //}
    //
    //@Override
    //protected WebApplicationContext createRootApplicationContext() {
    //    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    //    context.register(SpringConfig.class);
    //    return context;
    //}
}
